<template>
    <div>
        <el-row>
            <el-col :span="24" class="base-mian-cell" v-if="presFlag">
                <div class="base-mian-cell-title clearfix">
                    <div class="left fl">
                        <span class="line">|</span>
                        <span class="tips">预核保</span>
                    </div>
                    <div class="right fr" @click="changeView">
                        <i class="el-icon-circle-close"></i>
                    </div>
                </div>
                <div class="base-mian-cell-main">
                    <el-table
                            :data="datas"
                            style="width: 100%">
                        <el-table-column prop="caseNum" label="案件号" min-width="300" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column  prop="mechanism" label="机构" min-width="120" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column  prop="caseNo" label="关联受理号" min-width="120" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column prop="busUserJobno" label="经办人工号"  min-width="120" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column  prop="busIdNum" label="证件号" min-width="200" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column  label="关联操作" min-width="100" >
                            <template slot-scope="scope">
                                <i class="el-icon-share" v-if="scope.row.caseNo==''" @click="shareOption(scope.row)" title="关联"></i>
                            </template>
                        </el-table-column>
						<el-table-column  v-if="caseNo!=''" min-width="120" label="预投保资料" align='center' show-overflow-tooltip>
							<template slot-scope="scope">
								<router-link style="color:#7FC1FD;" :to="{name: 'insuranceDetail', params: {taskNo:scope.row.taskNo,prepNo:scope.row.prepNo,routeid:scope.row.routeid,caseNum:scope.row.caseNum,dealTime:scope.row.dealTime}}">案件详情</router-link>
							</template>
						</el-table-column>
                    </el-table>
                </div>
            </el-col>
        </el-row>

        <!-- 预核保关联 -->
        <el-dialog
                title="关联"
                :visible.sync="opinionDialogVisible6"
                width="60%"
                center>
            <el-row class="mb10">
                <el-col :span="4">
                    <label class="complain-lab">预核保号</label>
                </el-col>
                <el-col :span="14">
                      <el-input v-model="shareInfo.caseid" readonly></el-input>
                </el-col>
            </el-row>
            <el-row class="mb10">
                <el-col :span="4">
                    <label class="complain-lab">受理号</label>
                </el-col>
                <el-col :span="14">
                            <el-select v-model="shareInfo.appnum" clearable placeholder="请选择">
                                <el-option
                                        v-for="item in applnums"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value">
                                </el-option>
                            </el-select>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" v-if="!isRead" @click="savePre">确 定</el-button>
            <el-button @click="opinionDialogVisible6 = false">返 回</el-button>
        </span>
        </el-dialog>


    </div>
</template>
<script>
  import constant from '@/utils/constant';
  import uwLoadJs from '@/utils/uwLoad';
  import appName from '@/api/appName';
export default {
    data(){
        return{
          opinionDialogVisible6:false,
          applnums:[],
          shareInfo:{
            caseid:"",
            appnum:""
          }
        }
    },
    props:{
      presFlag: {
           type: Boolean,
           default: false
        } ,
      isRead: {
           type: Boolean,
           default: false
        } ,
      applnum: {
           type: String,
           default: ""
        } ,
      cardno: {
           type: String,
           default: ""
        } ,
      datas: {
           type: Array,
           default(){
             return [];
           }
        }
    },
    methods:{
        changeView(){
            this.$emit('subPreFlag',false);
        },

      shareOption(data){
          debugger
          this.shareInfo.caseid = data.prepNo;
          this.opinionDialogVisible6 = true;
      },
      //关联操作
      savePre(){
          let that = this;
        if(this.shareInfo.appnum==""){
          this.$message({
            message: "请选择受理号",
            type: 'error'
          });
          return false;
        }
        for(let i=0;i<this.datas.length;i++){
          let item = this.datas[i];
          if(item.caseNo!="" && item.caseNo==this.shareInfo.appnum){
            this.$message({
              message: "该受理号已有关联案件号"+item.prepNo,
              type: 'error'
            });
            return false;
          }
        }

        let params= {
          "caseId":this.shareInfo.caseid,
          "appnum":this.shareInfo.appnum
        }
        that.$emit('showLoading',true);
        let url = appName.TASK + '/advance/task/preRelation';
        let res = uwLoadJs.ajaxRequest(params,url);
        that.$emit('showLoading',false);
        if(res==null){

        }else if (res.resultCode == constant.SUCCESS && res.resultMsg) {
          this.$message({
            message: res.resultMsg,
            type: 'success'
          });
          this.opinionDialogVisible6 = false;
          this.initData();
        }else{
          if(res.resultMsg){
            this.$message({
              message: res.resultMsg,
              type: 'error'
            });
          }

        }
      },

      initData(){
          let that= this;
          if(this.cardno){
            // this.cardno = '123';
            let params = {
              "idNum":this.cardno
            }
            that.$emit('showLoading',true);
            let url = appName.TASK + '/advance/task/preQueryListByIdNum';
            let res = uwLoadJs.ajaxRequest(params,url);
            that.$emit('showLoading',false);
            if(res==null){

            }else if(res.data){
              this.datas = [];
              for(let i=0;i<res.data.length;i++){
                let item = res.data[i];
                if(!item.caseNo){
                  item.caseNo = "";
                }
                this.datas.push(item);
              }
              // this.$emit('initPre',this.datas);
            }
          }
      }
    },
  created() {
    this.applnums=[];
    if(this.applnum.indexOf("_")>0){
      let arr = this.applnum.split("_");
      for(let i=0;i<arr.length;i++){
        let option={
          "label":arr[i],
          "value":arr[i],
        }
        this.applnums.push(option);
      }
    }else{
      let option={
        "label":this.applnum,
        "value":this.applnum,
      }
      this.applnums.push(option);
    }
  }
}
</script>